<?php


namespace app\common\command;


use app\sys\model\Fun;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Container;
use think\Db;
use think\Exception;

class GetFun extends Command
{
    protected function configure()
    {
        $this->setName('get_fun')
            ->setDescription('功能拉取（功能权限）');
    }

    protected function execute(Input $input, Output $output)
    {
        $routeList = Container::get('route')->getRuleList();
        Db::startTrans();
        try {
            foreach ($routeList as $k1 => $v1) {
                foreach ($v1 as $k => $v) {
                    Fun::add($v["rule"], $v["name"]);
                }
            }
            Db::commit();
            $output->writeln("get_fun success");
        }catch ( \Exception $exception){
            Db::rollback();
            $output->writeln("get_fun false");
        }
    }

}